# file mcf2.mod
# min-cost flow instance with capacities on the arcs

param n;     # Number of nodes;

set ARCS within {1..n, 1..n};

param supply {1..n};

check: sum {i in 1..n} supply[i] = 0;
### This statement will check that the sum of demands is zero

param cost {ARCS};
param u {ARCS};

# notice the capacity constraints
var x {(i,j) in ARCS} >=0, <= u[i,j];

minimize total_cost:
    sum { (i,j) in ARCS } cost[i,j]*x[i,j];
subject to balance {i in 1..n}:
sum{ (i,j) in ARCS } x[i,j] - sum { (j,i) in ARCS } x[j,i]   = supply[i];
